<?php
class Site {
	
	function __construct () {}
	
	/*******************************************************************
	 * Page utils
	 * *****************************************************************/
	
	function searchLabelPage($label){
		global $_DB;
		$page = $_DB->query("SELECT COUNT(id) FROM ".$_DB->getPrefix()."pages WHERE label LIKE '".$label."'");
		
		if ($page[0][0] == 0) {
			return true;
		} else {
			return false;
		}
	}
	
	function getThreePages ($livel, $parent, &$three = null) {
		global $_DB;
		$livel++;
		//echo 'livel: '.$livel.' parent: '.$parent.' count: '.count($this->page_id)."\n";
		
		$pages = $_DB->query("SELECT id, parent, name FROM ".$_DB->getPrefix()."pages WHERE parent = '".$parent."' AND deleted = '0' ORDER BY sort");
		
		foreach ($pages as $p) {
			$ele[0]["id"] = $p["id"];
			$ele[0]["name"] = $p["name"];
			$ele[0]["livel"] = $livel-1;
			
			$three[] = $ele[0];
			
			$this->getThreePages($livel, $p["id"], $three);
		}
		
		return $three;
	}
	
	
	/*******************************************************************
	 * Users utils
	 * *****************************************************************/
	
	function getUsers(){
		global $_DB;
		
		$users = $_DB->query("SELECT id, nick FROM ".$_DB->getPrefix()."users ORDER BY nick ASC");
		foreach ($users as $u) {
			$ele["nick"] = $u["nick"];
			$ele["id"] = $u["id"];
			
			$returnUsers[] = $ele;
		}
		
		return $returnUsers;
	}
}
?>